﻿using System;
using System.Security.Claims;
using System.Threading;
using CarShop.Security.Contracts;

namespace CarShop.UserInterface.Wpf.Core.Infrastructure
{
    public class AuthenticationService : IAuthenticationService
    {
        public void SignIn(CarShopIdentity identity, bool remember = false)
        {
            CarShopPrincipal carShopPrincipal = Thread.CurrentPrincipal as CarShopPrincipal;

            if (carShopPrincipal == null)
                throw new ArgumentException("The application's default thread principal must be set to a CarShopPrincipal object on startup.");

            carShopPrincipal.Identity = identity;
        }

        public void SignOut()
        {
            CarShopPrincipal carShopPrincipal = Thread.CurrentPrincipal as CarShopPrincipal;
            carShopPrincipal.Identity = new CarShopIdentity(0, "", new string[0]);
        }
    }
}
